const {
    ipcRenderer
} = require('electron');
const Timer = require('timer.js')

function startWork(){
    let workTimer = new Timer({
        ontick:()=>{
            updateTime()
        },
        onend:()=>{
            notification()
        }
    })

    workTimer.start(10)
}


function updateTime(ms) {
    let timeContainer = document.getElementById('time-container');
    timeContainer.innerHTML = ms;
}

async function notification(){
    let res = await ipcRenderer.invoke('work-notification');
    if(res === 'rest')
    {
        setTimeout(()=>{
            alert('休息')
        }, 5*1000);
    }else if (res === 'work'){
        startWork();
    }
}

startWork();
